package com.hzcx.app.simplechat.ui.friend.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.ui.friend.bean.FriendCityBean;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;
import com.hzcx.app.simplechat.util.glide.GlideUtils;

import java.util.List;

public class FriendSortAdapter extends BaseQuickAdapter<FriendCityBean, BaseViewHolder> {

    private boolean isShowCheckBox;

    public FriendSortAdapter(@Nullable List<FriendCityBean> data) {
        this(data, false);
    }

    public FriendSortAdapter(@Nullable List<FriendCityBean> data, boolean isShowCheckBox) {
        super(R.layout.rv_item_friend_sort, data);
        this.isShowCheckBox = isShowCheckBox;
    }

    @Override
    protected void convert(BaseViewHolder helper, FriendCityBean item) {
        helper.setText(R.id.tv_nick_name, EmptyUtils.isNotEmpty(item.getRemarks_name()) ? item.getRemarks_name() : item.getNickname());
        GlideUtils.loadImg(mContext, item.getAvatar(), helper.getView(R.id.iv_head));
        helper.setText(R.id.tv_state, item.getOnline_time());

        ImageView ivCheckBox = helper.getView(R.id.iv_check_box);
        if (isShowCheckBox) {
            ivCheckBox.setVisibility(View.VISIBLE);
        } else {
            ivCheckBox.setVisibility(View.GONE);
        }

        if (item.isChecked()) {
            ivCheckBox.setImageResource(R.mipmap.ic_icon_check_select);
        } else {
            ivCheckBox.setImageResource(R.mipmap.ic_icon_check_normal);
        }
    }
}
